import { Toast } from 'antd-mobile'

// 防重复点击装饰器
export function Throttle(wait: number = 300) {
  return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    const originalMethod = descriptor.value
    let lastTime = 0

    descriptor.value = function (...args: any[]) {
      const now = Date.now()
      if (now - lastTime >= wait) {
        lastTime = now
        return originalMethod.apply(this, args)
      } else {
        Toast.show({
          content: '请勿频繁操作',
          position: 'bottom'
        })
      }
    }

    return descriptor
  }
}